﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DLL.Entities;
using System.Xml;
using System.Xml.Serialization; 


namespace MIS
{
    public partial class MIS_Form : Form
    {
        Radar Missile = new Radar();
        private int numMis = 5;
        private Boolean loadMiss = false;

        public MIS_Form()
        {
            InitializeComponent();
            
        }

        private void MIS_Form_Load(object sender, EventArgs e)
        {
            

        }

        private void btnFire_Click(object sender, EventArgs e)
        {
            btnFire.Enabled = false;
            btnLoad.Enabled = true;
            txtResult.Text = "Target Destroyed";
            if (numMis <= 0)
            {
                MessageBox.Show("No Missiles Remaining");
                btnFire.Enabled = false;
                btnLoad.Enabled = false;
            }
        }
         private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                XmlReader reader2 = new XmlTextReader("../../../Missle.xml");
                XmlSerializer serializer2 = new XmlSerializer(typeof(Radar));
                Missile = (Radar)serializer2.Deserialize(reader2);
                reader2.Close();
            }
            catch (Exception ex) 
            {

            }
        }
        private int RandomNumber(int min, int max)
        {
            Random random = new Random();
            return random.Next(min, max); 
        }

        private void timer1_Tick_1(object sender, EventArgs e)
        {
            Missile misStat = new Missile();
            misStat.missileStat = Convert.ToString(DateTime.Now);
            XmlSerializer serialization = new XmlSerializer(typeof(Missile));
            XMLHandler.WriteXML(misStat, "missileStat_Serialized.xml", serialization);

        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            btnLoad.Enabled = false;
            btnFire.Enabled = true;
            txtResult.Clear();
            if (numMis > 0)
            {
                numMis--;
                loadMiss = true;
                txtNumMis.Text = Convert.ToString(numMis);
            }
            if (loadMiss == true)
            {
                MessageBox.Show("Loaded");                
            }
            if (numMis <= 0)
            {
                btnLoad.Enabled = false; 
            }                 
            
               
                
            
        }

       
    }    
}
